package com.ly.common.running.factory;

import com.ly.common.business.util.SpringContextUtil;
import com.ly.common.running.exception.BusinessException;
import com.ly.common.running.impl.IBaseFlowHandle;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author luoyana
 * @version V1.0
 * @ClassName BusiFlowHandleFactory
 * @description Flow业务流程工厂
 * @update 2023/6/8
 */
@Service
public class BusiFlowHandleFactory implements ApplicationContextAware {
    public static Map<String,IBaseFlowHandle> baseFlowHandleMap;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        baseFlowHandleMap = applicationContext.getBeansOfType(IBaseFlowHandle.class);
    }
    public static IBaseFlowHandle getValue(String key){
        for(String var : baseFlowHandleMap.keySet()){
            boolean flag = baseFlowHandleMap.get(var).getKey().equals(key);
            if(flag){
                return baseFlowHandleMap.get(var);
            }
        }
        throw new BusinessException("SC0003");
    }
}
